<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%String skin = (String) session.getAttribute("USERSKIN_SESSION");%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <%--<meta name="viewport" content="width=device-width, initial-scale=1.0" />--%>
    <title>陕西省车驾管业务电子缴费系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <jsp:include page="/inc/head.jsp" flush="true"/>
    <jsp:include page="/inc/footer.jsp" flush="true"/>
    <script src="${basePath}/js/bootstrap-treeview/js/bootstrap-treeview.js"></script>
</head>
<body class="hold-transition skin-blue sidebar-mini" >
<div class="container" >
    <div id="AddRoleModal" class="modal fade bs-example-modal-lg addUpdateInfo" role="dialog" aria-labelledby="myLargeModalLabel">
        <div class="modal-dialog " role="document">
            <div class="modal-content" style="width: 700px;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel" >添加角色/编辑角色</h4>
                </div>
                <div class="modal-body" style="height: 600px;">
                    <form id="fileSearchForm" data-toggle="validator" enctype="multipart/form-data">
                        <div class="form-inline" style="margin-bottom: 15px">
                            <label style="margin-right: 20px" >角色名称</label>
                            <input class="form-control " type='text' id='roleName' placeholder="必填项" name='itemCaseNum' value=''>
                        </div>
                        <div  class="form-inline" style="margin-bottom: 15px">
                            <label style="margin-right: 20px">角色描述</label>
                            <textarea class="form-control" rows="3" id="roleDescription" name=textarea style="height: 40px;width: 500px;"></textarea>
                        </div>
                       <div class="form-inline"style="margin-right: 30px;margin-top: 15px;margin-bottom: 5px">
                            <label style="margin-right: 20px">权限选择</label>
                           <textarea class="form-control " rows="3" id="resourceChoose" name=textarea style="height: 80px;width: 500px;" readonly></textarea>
                           <div id="menuTree" style="height: 50px;width: 500px;margin-left: 80px ;font-size: 12px"></div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer bg-info">
                    <button type="button" class="btn green" data-dismiss="modal">取消</button>
                    <button type="button" class="btn blue" id="searchFile" onclick="addRoleAction()">确认</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
function checkParentManager(){
    var addParentManList=$("#addParentManList").find(":selected").val();
    $.ajax({
        type: "POST",
        url: "/pcwindow/findVehcicleManageByParent",
        dataType: "json",
        data:{ mdId : addParentManList },
        success: function (data) {
            if (data.length > 0) {
                var ManagerDepartment = data;
                $("#addVehicleList").find("option").remove();
                var str =  '<option value="0"> -- 请选择管理部门信息 --</option>';
                for (var i = 0; i < ManagerDepartment.length; i++) {
                    var mdName = ManagerDepartment[i].mdName;
                    var mdCode = ManagerDepartment[i].mdCode;
                    str += '<option value="' + mdCode + '">' + mdName + '</option>'
                }
                $('#addVehicleList').html(str);
            }
        }
    })
}
function addRoleAction() {
    var roleName=$("#roleName").val();
    var roleDescription=$("#roleDescription").val();
    var resourcesCode=$("#resourceChoose").val();
    var roId=$("#roId").val();
    var flag;
    if(roId == ""){
        flag =0;
    }else{
        flag =1;
    }
    if(roleName == ""){
        alert("角色名称不能为空");
    }else if(roleDescription == ""){
        alert("角色描述不能为空");
    }else if(resourcesCode == ""){
        alert("请选择权限");
    }else{
        $.ajax({
            type: "POST",
            url: "/pcwindow/roleManagerSet",
            dataType: "json",
            data:{
                flag :flag,
                roleId : roId,
                roleName : roleName,
                roleDescription : roleDescription ,
                resourcesCode : resourcesCode ,
            },
            success: function (data) {
                if (data.status ==200) {
                    if(flag != 0){
                       // alert("编辑成功");
                        $('#AddRoleModal').modal("hide")
                        $("#roId").val("");
                        $("#table").bootstrapTable('refresh');
                    }else{
                       // alert("添加成功");
                        $('#AddRoleModal').modal("hide")
                        $("#table").bootstrapTable('refresh');
                    }
                }
            }
        });
    }
 }
 function roleMessageShow(roId) {
       $("#roId").val(roId);
        $.ajax({
            type: "POST",
            url: "/pcwindow/findRoleByRoId",
            dataType: "json",
            data:{
                roId : roId,
            },
            success: function (data) {
                if (data.length != 0) {
                    var role = data.Role;
                    var resourceStr = data.resourStr;
                    $("#roleName").val(role.roName);
                    $("#roleDescription").val(role.roDescribe);
                    $("#resourceChoose").val(resourceStr);
                    $('#AddRoleModal').modal("show");
                }
            }
        });
 }
//bootstrap-treeview,暂时不用
$(function () {
    $.ajax({
        type: "POST",
        url:"/pcwindow/permissionTree",
        dataType:"json",
        success:function (result) {
                $('#menuTree').treeview({
                    data: result,// 树形菜单数据
                    emptyIcon: "glyphicon",
                    levels: 1, //展开层级
                    backColor: "#000000", // 背景
                    color: "", // 文本颜色
                    selectable: true,
                   state: {
                        checked: false,
                        disabled: false,
                        expanded: false,
                        selected: false
                    },
                    showBorder: false,
                    checkedIcon: "glyphicon glyphicon-check", //节点被选中时显示的图标         String
                    collapseIcon: "glyphicon glyphicon-minus", //节点被折叠时显示的图标        String
                    expandIcon: "glyphicon glyphicon-plus", //节点展开时显示的图标        String
                    showCheckbox: true,
                    onNodeSelected: function(event, data) {
                        // 重置收缩展开
                        if (data.nodes != null) {
                            var select_node = $('#menuTree').treeview('getSelected');
                            if (select_node[0].state.expanded) {
                                $('#menuTree').treeview('collapseNode', select_node);
                                select_node[0].state.selected = false;
                            } else {
                                $('#menuTree').treeview('expandNode', select_node);
                                select_node[0].state.selected = false;
                            }
                            }
                        loadInputText(data);
                        }
                });
        }
    })
})

    function loadInputText(data) {
        if(data.length != 0) {
            var text = data.text;
            var Pid = data.Pid;
            var id =data.id;
            if(Pid == 0){
                if(id == 1||text == "主控制台"){
                    var arrNew = new Array();
                    if ($("#resourceChoose").val() == "") {
                        $("#resourceChoose").val(text);
                    } else {
                        var textArr = $("#resourceChoose").val();
                        var result = textArr.split(",");
                        for(var i = 0; i < result.length; i++){
                            if (result[i] == text) {
                                for(var j = 0; j < result.length; j++){
                                    if(result[i] != result[j]) {
                                        arrNew.push(result[j]);
                                    }
                                }
                                $("#resourceChoose").val("");
                                $("#resourceChoose").val(arrNew);
                                return;
                            }
                        }
                        textArr += "," + text;
                        $("#resourceChoose").val(textArr);
                    }
                }
                return;
            }else{
                var arrNew = new Array();
                if ($("#resourceChoose").val() == "") {
                    $("#resourceChoose").val(text);
                } else {
                    var textArr = $("#resourceChoose").val();
                    var result = textArr.split(",");
                    for(var i = 0; i < result.length; i++){
                        if (result[i] == text) {
                            for(var j = 0; j < result.length; j++){
                                if(result[i] != result[j]) {
                                    arrNew.push(result[j]);
                                }
                            }
                            $("#resourceChoose").val("");
                            $("#resourceChoose").val(arrNew);
                            return;
                        }
                    }
                    textArr += "," + text;
                    $("#resourceChoose").val(textArr);
                }
            }
        }
    }

    /*function loadInputText(data) {
        if(data.text != "") {
            var text = data.text;
            if ($("#resourceChoose").val() == "") {
                $("#resourceChoose").val(text);
            } else {
                var textArr = $("#resourceChoose").val();
                var result = textArr.split(",");
                var arrNew = new Array();
                for (var i = 0; i < result.length; i++) {
                    if (result[i] == text) {
                       for(var j = 0; j < result.length; j++){
                           if(result[i] != result[j]) {
                               arrNew.push(result[j]);
                           }
                       }
                        $("#resourceChoose").val("");
                        $("#resourceChoose").val(arrNew);
                        return;
                    }
                    if(text == "用户列表" || text == "角色管理"){
                        if (result[i] == "用户管理") {
                            return;
                        }
                    }
                    if(text == "用户管理"){
                        if(result[i] == "西安市车驾管业务订单" || result[i] == "陕西省车驾管业务订单"){
                            return;
                        }
                    }
                    if(text == "西安市车驾管业务订单" || text == "陕西省车驾管业务订单"){
                        if (result[i] == "订单管理") {
                            return;
                        }
                    }
                    if(text == "订单管理"){
                        if(result[i] == "西安市车驾管业务订单" || result[i] == "陕西省车驾管业务订单"){
                            return;
                        }
                    }
                    if(text == "地市业务管理"){
                        if (result[i] == "业务控制管理") {
                            return;
                        }
                    }
                    if(text == "业务控制管理"){
                        if(result[i] == "地市业务管理"){
                            return;
                        }
                    }
                    if(text == "业务统计表单" ){
                        if (result[i] == "业务统计明细表") {
                            return;
                        }
                    }
                    if(text == "业务统计明细表"){
                        if(result[i] == "业务统计表单"){
                            return;
                        }
                    }
                    if(text == "收费类目统计明细表" || text == "资金去向户统计明细表"){
                        if (result[i] == "财务统计表单") {
                            return;
                        }
                    }
                    if(text == "财务统计表单"){
                        if(result[i] == "收费类目统计明细表" || result[i] == "资金去向户统计明细表"){
                            return;
                        }
                    }
                    if(text == "核账收款表" || text == "收款审核表" || text == "退款明细表"){
                        if (result[i] == "核账收款") {
                            return;
                        }
                    }
                    if(text == "核账收款"){
                        if(result[i] == "核账收款表" || result[i] == "收款审核表" || result[i] == "退款明细表"){
                            return;
                        }
                    }

                }
                textArr += "," + text;
                $("#resourceChoose").val(textArr);
            }
        }
    }*/
</script>
</body>
</html>

